<?php
namespace mobile\controllers;

use frontend\models\ArtForm;
use Yii;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\helpers\Url;
use yii\web\Controller;
use yii\web\Response;
use yii\base\ErrorException;
use yii\helpers\Html;
use common\widgets\file_upload\FileUpload;
use common\models\member\Member;
use common\models\category\Category;
use common\models\articles\Articles;
use common\models\art\Art;
use common\models\meeting\Meeting;
use yii\data\Pagination;
use yii\web\Request;

class ListController extends Controller
{     
	 public $layout = 'main';
	public function actions()
    {
        return [
            'upload'=>[
                'class' => 'common\widgets\file_upload\UploadAction',     //这里扩展地址别写错
                'config' => [
                ]
            ],
			'ueditor'=>[
				'class' => 'common\widgets\ueditor\UeditorAction',
				'config'=>[
					//上传图片配置
					'imageUrlPrefix' => "", /* 图片访问路径前缀 */
					'imagePathFormat' => "/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
				]
			]
        ];
    }

    /**
    * 新闻列表 zsn 20161229
    */
  public function actionNews($id){

$cat = Category::find()->where(['id'=>$id])->asArray()->one();

   if($cat['parent_id'] == 0)
   {
     $ccat = Category::find()->where(['status'=>1,'parent_id'=>$id])->asArray()->one();
     if($ccat){
      $childcat = Category::find()->where(['status'=>1,'parent_id'=>$id])->asArray()->all();
       foreach ($childcat as $key=>$arr){
         $ccid = $arr['id'];
         $cccat = Category::find()->where(['status'=>1,'parent_id'=>$ccid])->asArray()->all();
         $childcat[$key]['zlm'] =$cccat;
       }
         $ppinfo = $cat;
         if(empty($childcat[0]['zlm'])){
           $parentinfo = 1;
           $cat = $childcat[0];
           $pid =$cat['id'];
         }else{
          $parentinfo = $childcat[0];
           $pid = $parentinfo['id'];
           $cat = $childcat[0]['zlm'][0];
         }
     }else{
       $childcat[0] =$cat;
       $ppinfo = $cat;
       $parentinfo = 1;
       $pid =$id;

     }

   }else{

    $pid = $cat['parent_id'];
    $pcat = Category::find()->where(['id'=>$pid])->asArray()->one();
     if($pcat['parent_id'] == 0){

       $pid = $pcat['id'];

       $childcat = Category::find()->where(['status'=>1,'parent_id'=>$pid])->asArray()->all();
       foreach ($childcat as $key=>$arr) {
         $ccid = $arr['id'];
         $cccat = Category::find()->where(['status' => 1, 'parent_id' => $ccid])->asArray()->all();
         $childcat[$key]['zlm'] = $cccat;
       }
       $catc = Category::find()->where(['status'=>1,'parent_id'=>$id])->asArray()->all();
       if($catc){
         $ppinfo = $pcat;
         $parentinfo =$cat;
         $cat = $catc[0];
       }else{
         $ppinfo = $pcat;
         $parentinfo = 1;
        //$cat 不变
       }
     }else {
      $ppid = $pcat['parent_id'];
       $childcat = Category::find()->where(['status'=>1,'parent_id'=>$ppid])->asArray()->all();
       foreach ($childcat as $key=>$arr) {
         $ccid = $arr['id'];
         $cccat = Category::find()->where(['status' => 1, 'parent_id' => $ccid])->asArray()->all();
         $childcat[$key]['zlm'] = $cccat;
       }
       $ppinfo = Category::find()->where(['id'=>$ppid])->asArray()->one();
       $parentinfo = $pcat;
       //$cat 位当前栏目
     }
   }



	 	$title = Category::find()->where(['id'=> $id])->asArray()->one()['name'];
	 	$ctype = Category::find()->where(['id'=> $id])->asArray()->one()['ctype'];
    $p_id = Category::find()->where(['id'=> $id])->asArray()->one()['parent_id'];
    $p_title = Category::find()->where(['id'=> $p_id])->asArray()->one()['name'];
    
	 	$cid =$cat['id'];

    $articles = Articles::find()->where(['category_id'=>$cid, 'status' => Articles::STATUS_ACTIVE])->limit(9)->asArray()->all();

    $z_two = Category::find()->where(['parent_id'=>$id])->asArray()->all();
    $id2=0;
    $id3=0;
    if(!empty($z_two)){
      //二级
      $z_class = 2;
    }else{
      //只有一级
      $z_class = 0;
    }
    if($_GET['z_nav']){
      //从二级点进来
        if($_GET['z_nav']==2){
          $id2 = $id;
          $z_this = Category::find()->where(['id'=>$id])->asArray()->one();
          $z_two = Category::find()->where(['parent_id'=>$z_this['parent_id']])->asArray()->all();
          $z_three = Category::find()->where(['parent_id'=>$z_this['id']])->asArray()->all();
          $z_class = 3;
        }
      //从三级点进来
        if($_GET['z_nav']==3){
          $id3 = $id;
          $z_this = Category::find()->where(['id'=>$id])->asArray()->one();
          $z_three = Category::find()->where(['parent_id'=>$z_this['parent_id']])->asArray()->all();
          $z_oneone = Category::find()->where(['id'=>$z_three[0]['parent_id']])->asArray()->one();
          $z_one = Category::find()->where(['id'=>$z_oneone['parent_id']])->asArray()->one();
          $z_two = Category::find()->where(['parent_id'=>$z_one['id']])->asArray()->all();
          $id2= $z_oneone['id'];
          $z_class = 3;
        }
    }
    $view = Yii::$app->view;
    $view->params['z_class'] = $z_class;
    if(isset($id2)){
        $view->params['id2'] = $id2; 
    } 
    if(isset($id3)){
        $view->params['id3'] = $id3; 
    } 
    if(isset($z_two)){
      $view->params['z_two'] = $z_two; 
    }
    if(isset($z_three)){
      $view->params['z_three'] = $z_three; 
    }
    

        return $this->render('news',[
          'z_nav' => $_GET['z_nav'],
          'cat' => $cat,
          'ppinfo' => $ppinfo,
          'id' => $id,
          'pid' => $pid,
          'ctype' => $ctype,
      'parentinfo'=>$parentinfo,
          'childcat' => $childcat,
          'articles' => $articles,

        ]);
  }

    /**
    * 新闻内页
    */
	public function actionNewscontent($id){

		$cid = Articles::find()->where(['id' => $id, 'status' => Articles::STATUS_ACTIVE])->asArray()->one()['category_id'];
		$pid =Category::find()->where(['status'=>1,'id'=>$cid])->asArray()->one()['parent_id'];
		if($pid == 0){
			$childcat = Category::find()->where(['status'=>1,'parent_id'=>$cid])->asArray()->All();
			$tid = $cid;
			$parentinfo = Category::find()->where([ 'id'=> $cid])->asArray()->one();
			// 当前栏目信息  $id
			$cat = Category::find()->where([ 'id'=> $cid])->asArray()->one();

		}else{
			$ppid = Category::find()->where(['status'=>1,'id'=>$pid])->asArray()->one()['parent_id'];
			if($ppid==0){
				$childcat = Category::find()->where(['status'=>1,'parent_id'=>$pid])->asArray()->All();
				$tid = $pid;
			}else{
				$childcat = Category::find()->where(['status'=>1,'parent_id'=>$ppid])->asArray()->All();
				$tid = $pid;
			}
			$parentinfo = Category::find()->where(['status'=> 1, 'id'=> $pid])->asArray()->one();
			// 当前栏目信息  $id
			$cat = Category::find()->where(['status'=> 1, 'id'=> $cid])->asArray()->one();
		}


		foreach($childcat as $key=>$cc){
			$cid = $cc['id'];
			$arr = Category::find()->where(['status'=>1,'parent_id'=>$cid])->asArray()->All();
			$childcat[$key]['zlm']=$arr;
		}
      $category_id = Articles::find()->where(['id' => $id])->asArray()->one()['category_id'];
      $articles = Articles::find()->where(['category_id' => $category_id, 'status' => Articles::STATUS_ACTIVE])->limit('5')->asArray()->all();
   		$article = Articles::find()->where(['id' => $id])->asArray()->one();

//一，二，三级导航 zsn 20170112
    $z_category = Articles::find()->where(['id'=>$id])->asArray()->one();
    $z_two = Category::find()->where(['parent_id'=>$z_category['category_id']])->asArray()->all();
    if(!empty($z_two)){
      //二级
      $z_class = 2;
    }else{
      //只有一级
      $z_class = 0;
    }
    if($_GET['z_nav']){
      //从二级点进来
        if($_GET['z_nav']==2){
          
          $z_this = Category::find()->where(['id'=>$z_category['category_id']])->asArray()->one();
          $z_two = Category::find()->where(['parent_id'=>$z_this['parent_id']])->asArray()->all();
          $z_three = Category::find()->where(['parent_id'=>$z_this['id']])->asArray()->all();
          $id2 = $z_category['category_id'];
          $z_class = 3;
        }
      //从三级点进来
        if($_GET['z_nav']==3){
          $z_this = Category::find()->where(['id'=>$z_category['category_id']])->asArray()->one();
          $z_three = Category::find()->where(['parent_id'=>$z_this['parent_id']])->asArray()->all();
          $z_oneone = Category::find()->where(['id'=>$z_three[0]['parent_id']])->asArray()->one();
          $z_one = Category::find()->where(['id'=>$z_oneone['parent_id']])->asArray()->one();
          $z_two = Category::find()->where(['parent_id'=>$z_one['id']])->asArray()->all();
          $id3 = $z_category['category_id'];
          $id2= $z_oneone['id'];
          $z_class = 3;
        }
    }
    $view = Yii::$app->view;
    $view->params['z_class'] = $z_class; 
    if(isset($id2)){
        $view->params['id2'] = $id2; 
    } 
    if(isset($id3)){
        $view->params['id3'] = $id3; 
    } 
    if(isset($z_two)){
      $view->params['z_two'] = $z_two; 
    }
    if(isset($z_three)){
      $view->params['z_three'] = $z_three; 
    }



   		return $this->render('newscontent',[
        'z_nav' => $_GET['z_nav'],
   			'id' => $id,
   			'tid' => $tid,
			'cat' => $cat,
			'parentinfo' => $parentinfo,
			'article' => $article,
			'articles' => $articles,
   			'childcat' => $childcat,

      ]);
  }



  /**
    * 视频列表 zsn 20170107
    */
  public function actionVideo($id){

    $terminfo = Category::find()->where(['id'=> $id])->asArray()->one();
    
    $query = Articles::find()->where(['category_id'=>$id, 'status' => Articles::STATUS_ACTIVE]);
    $count = $query->count();
    $page = new Pagination(['totalCount' => $count, 'pageSize' => '6']);
    $articles = $query->offset($page->offset)
        ->limit($page->limit)
        ->all();
        return $this->render('Video',[
          'id' => $id,
          'terminfo' => $terminfo,
          'articles' => $articles,
          'page' => $page,
        ]);
  }

    /**
    * 视频内页
    */
  public function actionVideocontent($id){
      $article = Articles::find()->where(['id' => $id])->asArray()->one();
      $terminfo = Category::find()->where(['id'=> $article['category_id']])->asArray()->one();

      //其他页三级导航需要这里有 zsn 20120112
      $z_class = 0;
      $view = Yii::$app->view;
      $view->params['z_class'] = $z_class; 
      
      return $this->render('Videocontent',[
        'id' => $id,
        'article' => $article,
        'terminfo' => $terminfo,

      ]);
  }


    /**
    * 教育培训列表
    */
   	public function actionTrain($id){
	 	if(Category::find()->where(['status'=> 1, 'id'=> $id])->asArray()->one()['parent_id'] == 0){
	 		$tid = $id;
	 		$childcat = Category::find()->where(['status'=> 1, 'parent_id'=> $id])->orderBy('sort DESC')->asArray()->all();
	 		$id = $childcat[0]['id'];
			$parenttitle = Category::find()->where(['status'=> 1, 'id'=> $tid])->asArray()->one()['name'];//添加
	 	}else{
	 		$parentid = Category::find()->where(['status'=> 1, 'id'=> $id])->asArray()->one()['parent_id'];
	 		$childcat = Category::find()->where(['status'=> 1, 'parent_id'=> $parentid])->orderBy('sort DESC')->asArray()->all();
	 		$tid = $parentid;
			$parenttitle = Category::find()->where(['status'=> 1, 'id'=> $parentid])->asArray()->one()['name'];//添加
	 	}
		
    // 当前栏目信息  $id
	 	$title = Category::find()->where(['status'=> 1, 'id'=> $id])->asArray()->one()['name'];
	 	$ctype = Category::find()->where(['status'=> 1, 'id'=> $id])->asArray()->one()['ctype'];

    // 当前栏目父栏目信息  $tid
    $parentinfo = Category::find()->where(['status'=> 1, 'id'=> $tid])->asArray()->one();

	 	$query = Meeting::find()->where(['enroll' => Meeting::IS_OPEN]);
		$count = $query->count();
		$page = new Pagination(['totalCount' => $count, 'pageSize' => '10']);
		$articles = $query->offset($page->offset)
		    ->limit($page->limit)
		    ->all();
    $view = Yii::$app->view;  
    $view->params['tid']=$tid; 
        return $this->render('train',[
        	'tid' => $tid,
        	'id' => $id,
        	'title' => $title,
			    'parenttitle'=>$parenttitle,
          'parentinfo' => $parentinfo,
        	'ctype' => $ctype,
          'childcat' => $childcat,
          'articles' => $articles,
          'page' => $page,
        ]);
   	}

    /**
    * 教育培训列表单页
    */
   	public function actionTraincontent($id){
   		$categoryid = Meeting::find()->where(['id' => $id, 'enroll' => Meeting::IS_OPEN])->asArray()->one()['category_id'];
   		$ctype = Category::find()->where(['id' => $categoryid])->asArray()->one()['ctype'];
      $parentid = Category::find()->where(['status'=> 1, 'id' => $categoryid])->asArray()->one()['parent_id'];
   		$parentinfo = Category::find()->where(['status'=> 1, 'id' => $parentid])->asArray()->one();
      $parenttitle = Category::find()->where(['status'=> 1, 'id' => $parentid])->asArray()->one()['name'];
      $currenttitle = Category::find()->where(['status'=> 1, 'id' => $categoryid])->asArray()->one()['name'];

      $childcat = Category::find()->where(['status' => 1, 'parent_id' => $parentid])->orderBy('sort DESC')->asArray()->all();
   		$article = Meeting::find()->where(['id' => $id])->asArray()->one();
      $title = Meeting::find()->where(['id' => $id])->asArray()->one()['title'];
      $view = Yii::$app->view;  
      $view->params['tid']=$parentid;
   		return $this->render('traincontent',[
        'id' => $id,
   			'tcid' => $categoryid,
   			'title' => $title,
   			'ctype' => $ctype,
   			'article' => $article,
   			'childcat' => $childcat,
        'parentinfo' => $parentinfo,
        'parenttitle' => $parenttitle,
        'currenttitle' => $currenttitle,
        ]);
   	}

   	/**
    * 会员风采
    */
   	public function actionMemberstyle($id){

    // 跳转到第一个子栏目
	 	if(Category::find()->where(['status'=> 1, 'id'=> $id])->asArray()->one()['parent_id'] == 0){
      // 如果为一级栏目就跳转
	 		$tid = $id;
	 		$childcat = Category::find()->where(['status'=> 1, 'parent_id'=> $id])->asArray()->all();
	 		$id = $childcat[0]['id'];
	 	}else{
	 		$parentid = Category::find()->where(['status'=> 1, 'id'=> $id])->asArray()->one()['parent_id'];
	 		$childcat = Category::find()->where(['status'=> 1, 'parent_id'=> $parentid])->orderBy('sort DESC')->asArray()->all();
	 		$tid = $parentid;
	 	}
    // 导航状态
    $view = Yii::$app->view;  
    $view->params['tid']=$tid;
	 	$title = Category::find()->where(['status'=> 1, 'id'=> $id])->asArray()->one()['name'];
    $parentinfo = Category::find()->where(['status'=> 1, 'id'=> $tid])->asArray()->one();
    $parenttitle = Category::find()->where(['status'=> 1, 'id'=> $tid])->asArray()->one()['name'];
	 	$ctype = Category::find()->where(['status'=> 1, 'id'=> $id])->asArray()->one()['ctype'];
    // 列表信息
	 	$query = Member::find()->where(['status' => Member::STATUS_SUCCESS]);
		$count = $query->count();
		$page = new Pagination(['totalCount' => $count, 'pageSize' => '10']);
		$articles = $query->offset($page->offset)
		    ->limit($page->limit)
		    ->all();
        return $this->render('memberstyle',[
        	'tid' => $tid,
        	'id' => $id,
        	'title' => $title,
          'parentid' => $tid,
          'parenttitle' => $parenttitle,
          'parentinfo' => $parentinfo,
        	'ctype' => $ctype,
          'childcat' => $childcat,
          'articles' => $articles,
          'page' => $page,
        ]);
   	}

   	/**
   	* 会员风采列表内页
   	*/
   	public function actionMembercontent($id){
   		$title = '会员简介';
      $parenttitle = '会员风采';
   		$data = Member::find()->where(['id' => $id, 'status' => Member::STATUS_SUCCESS])->asArray()->one();
   		$parentid = 20;
      $parentinfo = Category::find()->where(['id'=> $parentid])->asArray()->one();
   		$tcid = 5;
   		$childcat = Category::find()->where(['status'=> 1, 'parent_id'=> $parentid])->orderBy('sort DESC')->asArray()->all();
      $view = Yii::$app->view;
      $view->params['tid'] = $tcid;
   		return $this->render('membercontent',[
   				'id' => $id,
   				'tcid' => $tcid,
          'parentid' => $parentid,
          'parentinfo' => $parentinfo,
   				'article' => $data,
   				'childcat' => $childcat,
   				'title' => $title,
          'parenttitle' => $parenttitle,
   			]);
   	}

    /**
    * 会员新闻列表
    */
   	public function actionNewsmember($id){
	 		
	 	// $view = Yii::$app->view;
	 	// $view->params['tid'] = $tid; 
	 	$title = '会员新闻';
	 	$categoryid = 5;
	 	$parentid = 20;
    $parentinfo = Category::find()->where(['id'=> $parentid])->asArray()->one();
	 	$parenttitle = '会员风采';
	 	$childcat = Category::find()->where(['status'=> 1, 'parent_id'=> $parentid])->orderBy('sort DESC')->asArray()->all();
	  $ctype = Category::find()->where(['status'=> 1, 'id'=> 32])->asArray()->one()['ctype'];


	 	$query = Art::find()->where(['status' => ArtForm::STATUS_ACTIVE, 'display' => ArtForm::DIS_SUCCESS, 'member_id'=> $id]);
		$count = $query->count();
		$page = new Pagination(['totalCount' => $count, 'pageSize' => '30']);
		$articles = $query->offset($page->offset)
		    ->limit($page->limit)
		    ->all();
        $view = Yii::$app->view;
        $view->params['tid'] = $categoryid;

        return $this->render('newsmember',[
   //      	'tid' => $tid,
         	  'id' => $id,
         	  'title' => $title,
            'parentid' => $parentid,
			      'parenttitle'=>$parenttitle,
            'parentinfo' => $parentinfo,
          	'ctype' => $ctype,
            'childcat' => $childcat,
            'articles' => $articles,
            'page' => $page,
        ]);
   	}

    /**
    * 会员新闻内页
    */
   	public function actionNewscontent1($id){
      // tid        一级栏目id
      // parentid   当前栏目父栏目id
      // currentid   当前栏目id
      // categoryid   会员id
      // title        会员名
      // parenttitle  当前栏目父栏目名


      $tid = 5;
      $parentid = 20;
      $currentid = 32;
      $parentinfo = Category::find()->where(['id' => $parentid])->asArray()->one();
   		$memberid = Art::find()->where(['id' => $id])->asArray()->one()['member_id'];
   		$title = Member::find()->where(['id' => $memberid])->asArray()->one()['username'];
      $currenttitle = Category::find()->where(['id' => $currentid])->asArray()->one()['name'];
      $currentinfo = Category::find()->where(['id' => $currentid])->asArray()->one();
      $parenttitle = Category::find()->where(['id' => $parentid])->asArray()->one()['name'];
   		$ctype = Category::find()->where(['id' => $memberid])->asArray()->one()['ctype'];
	 	  $childcat = Category::find()->where(['status' => 1, 'parent_id' => $parentid])->orderBy('sort DESC')->asArray()->all();
		
    /**
		* 文章上一篇和下一篇
		*/

		$articles = Art::find()->where(['member_id' => $memberid, 'status' => ArtForm::STATUS_ACTIVE, 'display' => ArtForm::DIS_SUCCESS])->asArray()->all();
		foreach($articles as $k=>$t){
			if($t['id'] == $id){
				//$lastone = $t[$k-1]['id'];
				$last = $k - 1;
				$next = $k + 1;
				//$nextone = $t[($k+1)]['id'];
			}
		}

		if(isset($articles[$last])) {
			$lastone['id'] = $articles[$last]['id'];
			$lastone['name'] = $articles[$last]['title'];
		} else {
			$lastone['id'] = $id;
			$lastone['name'] = '没有了';
		}

		if(isset($articles[$next])) {
			$nextone['id'] = $articles[$next]['id'];
			$nextone['name'] = $articles[$next]['title'];
		} else {
			$nextone['id'] = $id;
			$nextone['name'] = '没有了';
		}

   		$article = Art::find()->where(['id' => $id])->asArray()->one();
      $view = Yii::$app->view;
      $view->params['tid'] = $tid;

   		return $this->render('newscontent1',[
        'id' => $memberid,
        'memberid' => $memberid,
   			'title' => $title,
        'parentid' => $parentid,
        'parenttitle' => $parenttitle,
        'parentinfo' => $parentinfo,
        'currentid' => $currentid,
        'currenttitle' => $currenttitle,
        'currentinfo' => $currentinfo,
   			'ctype' => $ctype,
   			'article' => $article,
   			'childcat' => $childcat,
   			'lastone' => $lastone,
   			'nextone' => $nextone,
        ]);
   	}
  public function actionSearch(){
      // 新闻id
      $id = 14;
      $title = Category::find()->where(['id' => $id])->asArray()->one()['name'];
      $parentid = Category::find()->where(['id' => $id])->asArray()->one()['parent_id'];
      $parentinfo = Category::find()->where(['id' => $parentid])->asArray()->one();
      $childcat = Category::find()->where(['parent_id' => $parentid, 'status' => Category::STATUS_ACTIVE])->orderBy('sort DESC')->asArray()->all();
      $query = Articles::find()->where(['category_id'=> $id, 'status' => Articles::STATUS_ACTIVE]);


      if (isset($_GET['keywords'])){
        $search = $_GET['keywords'];
        $query = $query->andWhere(['like', 'title', $search]);
      }
      $count = $query->count();
      $page = new Pagination(['totalCount' => $count, 'pageSize' => '30']);
      $articles = $query->offset($page->offset)
          ->limit($page->limit)
          ->all();
      return $this->render('search',[
        'id' => $id,
        'title' => $title,
        'parentinfo'=>$parentinfo,
        'childcat' => $childcat,
        'articles' => $articles,
        'page' => $page,
      ]);
  }
    /**
    * 各委员会
    */
  public function actionWeiyuan($id){

    /*    $tid     父栏目id
          $id      当前栏目id
    */
      // 是否跳转到子栏目
    if(Category::find()->where(['status'=> 1, 'id'=> $id])->asArray()->one()['parent_id'] == 0){
      $tid = $id;
      $childcat = Category::find()->where(['status'=> 1, 'parent_id'=> $id])->orderBy('sort DESC')->asArray()->all();
      $id = $childcat[0]['id'];
      $parenttitle = Category::find()->where(['status'=> 1, 'id'=> $tid])->asArray()->one()['name'];
      $parentinfo = Category::find()->where(['status'=> 1, 'id'=> $tid])->asArray()->one();
    }else{
      $parentid = Category::find()->where(['status'=> 1, 'id'=> $id])->asArray()->one()['parent_id'];
      $childcat = Category::find()->where(['status'=> 1, 'parent_id'=> $parentid])->orderBy('sort DESC')->asArray()->all();
      $tid = $parentid;
      $parenttitle = Category::find()->where(['status'=> 1, 'id'=> $parentid])->asArray()->one()['name'];
      $parentinfo = Category::find()->where(['status'=> 1, 'id'=> $parentid])->asArray()->one();
    }

    // 判断导航状态
    $view = Yii::$app->view;
    $view->params['tid'] = $tid; 

    $title = Category::find()->where(['status'=> 1, 'id'=> $id])->asArray()->one()['name'];
    $ctype = Category::find()->where(['status'=> 1, 'id'=> $id])->asArray()->one()['ctype'];

    
    $query = Articles::find()->where(['category_id'=>$id, 'status' => Articles::STATUS_ACTIVE]);
    $count = $query->count();
    $page = new Pagination(['totalCount' => $count, 'pageSize' => '30']);
    $articles = $query->offset($page->offset)
        ->limit($page->limit)
        ->all();
        $view = Yii::$app->view;  
        $view->params['tid']=$tid;
        return $this->render('weiyuan',[
          'tid' => $tid,
          'id' => $id,
          'title' => $title,
          'parenttitle'=>$parenttitle,
          'parentinfo'=>$parentinfo,
          'ctype' => $ctype,
          'childcat' => $childcat,
          'articles' => $articles,
          'page' => $page,
        ]);
  }

    public function actionZenjia(){
        $num = $_GET['articlecount'];
        $cid = $_GET['id'];

        $count = Yii::$app->db->createCommand("SELECT count(*) FROM articles WHERE status = 10 and category_id = $cid")
            ->queryScalar();

        $articles = Yii::$app->db->createCommand("SELECT * FROM articles WHERE status = 10 and category_id = $cid limit $num,9")
            ->queryall();
//        echo $num;
//       echo 22;
        foreach ($articles as $key=>$arr){
            if($count<=($num+9)) {
                $result[$key] = array(
                    'id' => $arr['id'],
                    'content' => 1,
                    'title' => $arr['title'],
                    'time' => date('Y-m-d H:i:s', $arr['created_at']),
                );
            }else{
                $result[$key] = array(
                    'id' => $arr['id'],
                    'content' => 2,
                    'title' => $arr['title'],
                    'time' => date('Y-m-d H:i:s', $arr['created_at']),
                );
            }

        }
        echo json_encode($result);

    }

}